const { merge } = require("webpack-merge");
const singleSpaDefaults = require("webpack-config-single-spa");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const path = require("path")

// webpack-config-single-spa.js 配置很简单，可以查看源码
module.exports = (webpackConfigEnv, argv) => {
  const orgName = "myspa";
  const defaultConfig = singleSpaDefaults({
    orgName,
    projectName: "root-config",
    webpackConfigEnv,
    argv,
    disableHtmlGeneration: true
  });

  const config = merge(defaultConfig, {
    // modify the webpack config however you'd like to by adding to this object
    plugins: [
      new HtmlWebpackPlugin({
        inject: false,
        template: "./src/index.ejs",
        templateParameters: {
          isLocal: webpackConfigEnv && webpackConfigEnv.isLocal,
          orgName,
        },
      }),
    ]
  })

  config.devServer = {
    // 配合history路由使用
    historyApiFallback: true,
    // 配置跨域访问
    headers: {
      "Access-Control-Allow-Origin": "*",
    },
    writeToDisk: true, 
    // client: {
    //   webSocketURL: {
    //     hostname: "localhost",
    //   },
    // },
    // 静态资源路径
    contentBase: path.resolve(process.cwd(), "dist"),
    host: "localhost",
    port: "9000"
  }

  return config
};
